package com.busibuilding.administrate.area.service;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.transaction.annotation.Transactional;

import com.busibuilding.administrate.area.dao.ProvinceDAO;
import com.busibuilding.administrate.area.vo.ProvinceCVO;
import com.busibuilding.common.exceptions.DAOException;
import com.busibuilding.common.exceptions.ServiceException;
import com.busibuilding.common.services.CommonServicesImpl;
import com.busibuilding.common.vo.ICommonVO;

/**
 * Class Name: ProvinceServiceImpl.java
 * Description: 
 * @author Lin Yanjun
 * @version 1.0
 * @since 1.0
 * Date: 2010-3-2
 */
@Transactional(rollbackForClassName={"Exception"})
public class ProvinceServiceImpl extends CommonServicesImpl implements
		ProvinceService {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3583275561188705643L;
	private static Logger logger = LogManager.getLogger(ProvinceServiceImpl.class);
	
	private ProvinceDAO dao;

	public void setDao(ProvinceDAO dao) {
		this.dao = dao;
	}

	@Override
	public int getRecordsCount(ICommonVO vo) throws ServiceException {
		int id = SQLMAP_COMMON_RESULT_ERROR;
		try {
			id = dao.getRecordsCount(vo);
		} catch (DAOException e) {
			logger.fatal(e.getErrorCode() + ":" + e.getErrorMessage());
			throw new ServiceException(SERVICE_ERROR_CODE_SEARCH_PROVINCE, e);
		} catch (Exception e) {
			logger.fatal(e);
			throw new ServiceException(SERVICE_ERROR_CODE_SEARCH_PROVINCE, e);
		}
		return id;
	}

	@Override
	public int createProvince(ICommonVO vo) throws ServiceException {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int deleteProvince(ICommonVO vo) throws ServiceException {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<ProvinceCVO> searchProvince(ICommonVO vo) throws ServiceException {
		List<ProvinceCVO> resultList = new ArrayList<ProvinceCVO>();
		try {
			resultList = dao.searchProvinceByCondition(vo);			
		} catch (DAOException e) {
			logger.fatal(e.getErrorCode() + ":" + e.getErrorMessage());
			throw new ServiceException(SERVICE_ERROR_CODE_SEARCH_PROVINCE, e);
		} catch (Exception e) {
			logger.fatal(e);
			throw new ServiceException(SERVICE_ERROR_CODE_SEARCH_PROVINCE, e);
		}
		return resultList;
	}

	@Override
	public List<ProvinceCVO> searchProvinceByPagination(ICommonVO vo)
			throws ServiceException {
		List<ProvinceCVO> resultList = new ArrayList<ProvinceCVO>();
		try {
			resultList = dao.searchProvinceByCondition(vo, vo.getMinIndex(), vo.getMaxIndex());			
		} catch (DAOException e) {
			logger.fatal(e.getErrorCode() + ":" + e.getErrorMessage());
			throw new ServiceException(SERVICE_ERROR_CODE_SEARCH_PROVINCE, e);
		} catch (Exception e) {
			logger.fatal(e);
			throw new ServiceException(SERVICE_ERROR_CODE_SEARCH_PROVINCE, e);
		}
		return resultList;
	}

	@Override
	public int updateProvince(ICommonVO vo) throws ServiceException {
		// TODO Auto-generated method stub
		return 0;
	}

}
